package com.liuxinlong.jobs;

import com.liuxinlong.constant.TimeFormatConstants;
import com.liuxinlong.modules.dao.UserStandardPermissionDao;
import com.liuxinlong.modules.entity.UserStandardPermission;
import com.liuxinlong.utils.TimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 使用quartz框架
 */
@Service
@Slf4j
@Component("expireFilePermissionTask")
public class ExpireFilePermissionTask {

    @Autowired
    private UserStandardPermissionDao userStandardPermissionDao;

    /**
     * 业务逻辑
     */
    public void reptilian(){
        log.info("expireFilePermissionJob start...");
        List<UserStandardPermission> userStandardPermissionList = userStandardPermissionDao.getStandardPermissionList();
        String currentDate = TimeUtils.getDate(TimeFormatConstants.YYYY_MM_DD);
        for (UserStandardPermission up: userStandardPermissionList) {
            String expireDate = up.getExpireTime().substring(0,10);
            if (StringUtils.compare(currentDate,expireDate) > 0) {
                userStandardPermissionDao.deleteById(up.getId());
            }
        }
        log.info("expireFilePermissionJob end...");
    }
}

